package run;

import java.sql.SQLException;

import util.CONFIG;
import dto.ExecStepDTO;
import executor.ProcExecutor;
import linker.ExecPlan;

public class LogParser {
	
	public static void main(String[] args) {

		try {
			while (ExecPlan.hasNext()) {
				ExecStepDTO step = ExecPlan.next();
				Modulo modulo = CONFIG.getModulos().get(step.modulo);
				if (modulo.run(step) == 0) {
					ExecPlan.mark();
				}
			}
			deleteFile();
		} catch (SQLException e) {
			System.out.println("ERROR: Problem connecting to database.");
			e.printStackTrace();
			System.exit(-2);
		}
	}

	private static void deleteFile() {
		ProcExecutor exec = new ProcExecutor();
		exec.runCMD("del /Q " + CONFIG.getPathArchivos() + "*.*");
		System.out.println("Archivos borrados");
	}
}